﻿using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;

namespace datatablegenerator.Common
{
    public  class FunctionResult
    {
        public bool Success
        {
            get;
            set;
        } = true;

        public string Content
        {
            get;
            set;
        } = "";         

        public object Datas
        {
            get;
            set;
        }

        public int TotalRows
        {
            get;
            set;
        }

        public override string ToString()
        {
            return string.Format("IsSuccess:{0}\r\nMessage Content:{2}\r\nData:{3}", Success, Content, Datas);
        }
       

        public T GetDatas<T>() where T : class
        {
            if (Datas is JToken)
            {
                return ((JToken)Datas).ToObject<T>();
            }

            if (Datas is string)
            {
                return JsonConvert.DeserializeObject<T>((string)Datas);
            }

            return Datas as T;
        }

    }
}
